#include <modules\system\system_module.h>

namespace DelGE
{
	namespace Modules
	{
		namespace System
		{
			SystemModule::SystemModule()
			{
				this->sName = "system";

				LoadModule();
			}

			SystemModule::~SystemModule()
			{
				UnloadModule();
			}

			void SystemModule::LoadModule()
			{
				#if defined(DELGE_PLATFORM_WIN32)
				// this is just a formality, you would not need to really set
				// a different interface for the system at run time.
				this->pWin32_Interface = new Win32SystemInterface(); 
				// Because we might as well...
				this->SetInterface(this->pWin32_Interface);
				#endif

				this->bIsMouseHidden = false;
			}

			void SystemModule::UnloadModule()
			{
				#if defined(DELGE_PLATFORM_WIN32)
				delete this->pWin32_Interface;
				#endif
			}

			#if defined(DELGE_PLATFORM_WIN32)
			Win32SystemInterface* SystemModule::GetInterface_Win32()
			{
				return this->pWin32_Interface;
			}
			#endif

			SystemWindow* SystemModule::CreateWindow(string sCaption, int iWidth, int iHeight, DelGESystemWindowStyle eStyle)
			{
				SystemWindow* pSystemWindow = ((SystemInterface*)this->pInterface)->CreateWindow(sCaption, iWidth, iHeight, eStyle);
				return pSystemWindow;
			}

			SystemTimer* SystemModule::CreateTimer()
			{
				SystemTimer* pSystemTimer = ((SystemInterface*)this->pInterface)->CreateTimer();
				return pSystemTimer;
			}

			void SystemModule::DestroyGadget(SystemGadget* pSystemGadget)
			{
				switch (pSystemGadget->GetGadgetType())
				{
				case DelGESystemGadgetType_Base:
					delete pSystemGadget;
					pSystemGadget = NULL;
					break;

				case DelGESystemGadgetType_Window:
					delete ((SystemWindow*)pSystemGadget);
					pSystemGadget = NULL;
					break;
				}
			}

			void SystemModule::DestroyTimer(SystemTimer* pSystemTimer)
			{
				delete pSystemTimer;
				pSystemTimer = NULL;
			}

			void SystemModule::Update()
			{
				((SystemInterface*)this->pInterface)->Update();
			}

			vector<SystemVideoMode> SystemModule::GetSupportedVideoModes()
			{
				return ((SystemInterface*)this->pInterface)->GetSupportedVideoModes();
			}

			SystemVideoMode SystemModule::GetCurrentVideoMode()
			{
				return ((SystemInterface*)this->pInterface)->GetCurrentVideoMode();
			}

			bool SystemModule::IsVideoModeSupported(const SystemVideoMode &systemVideoMode)
			{
				return ((SystemInterface*)this->pInterface)->IsVideoModeSupported(systemVideoMode);
			}

			void SystemModule::ChangeVideoMode(const SystemVideoMode &systemVideoMode)
			{
				((SystemInterface*)this->pInterface)->ChangeVideoMode(systemVideoMode);
			}

			void SystemModule::RestoreVideoMode()
			{
				((SystemInterface*)this->pInterface)->RestoreVideoMode();
			}

			SystemVideoMode SystemModule::FindNearestSupportedVideoMode(const SystemVideoMode &systemVideoMode)
			{
				return ((SystemInterface*)this->pInterface)->FindNearestSupportedVideoMode(systemVideoMode);
			}

			void SystemModule::HideMouse()
			{
				((SystemInterface*)this->pInterface)->HideMouse();
				this->bIsMouseHidden = true;
			}

			void SystemModule::ShowMouse()
			{
				((SystemInterface*)this->pInterface)->ShowMouse();
				this->bIsMouseHidden = false;
			}

			bool SystemModule::IsMouseHidden()
			{
				return this->bIsMouseHidden;
			}
		}
	}
}